package com.yy.cloud.api;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.sql.SQLException;

/**
 * @date 2024/5/6
 */
@RestController
public class TestController {

    @Resource
    private DataSource dataSource; // 数据库的连接配置项在配置中心配着

    @Value("${version.v}")
    private String version; // 读取配置中心中配置的自定义属性值

    /**
     * 测试数据库是否连接成功
     */
    @GetMapping("/datasource")
    public String dataSource() throws SQLException {
        String datasourceClass = dataSource.getClass().toString();
        boolean haveConnection = dataSource.getConnection() != null;
        return "数据源类型：" + datasourceClass + ",是否连接成功：" + haveConnection + ", version " + version;
    }
}
